package gui;

import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.util.ArrayList;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;

import fiziksobject.Springs;

import physics.PhysicsEngine;
import physics.physicsobject;

public class SpringProperties extends ForcerEditor<Springs> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private ArrayList<physicsobject> fiziks;
	private NumberInput springConst;
	private LocationInput fixedPt;
	private JComboBox fiziksballs;
	private SpringProperties thiz = this;
	public SpringProperties(final Springs s){
		super(s);
		setLayout(new BoxLayout(getContentPane(),BoxLayout.Y_AXIS));

		fiziks = PhysicsEngine.getPhysicsEngine().getPhysicsObjects();
		springConst = new NumberInput("Spring Constant K (N/m)",s.getspringConstant());
		fixedPt = new LocationInput("Location", s.getSpringLoc());
		fiziksballs = new JComboBox(fiziks.toArray());
		add(springConst);
		add(fixedPt);
		add(fiziksballs);
		JButton ok = new JButton("Ok");
		ok.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent ae) {
				s.setMassOnSpring((physicsobject) fiziksballs.getSelectedItem());
				s.setSpringConst(springConst.getNum());
				s.setSpringLoc(fixedPt.getLoc());
				WindowEvent wev = new WindowEvent(thiz, WindowEvent.WINDOW_CLOSING);
                Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev);
			}
		});
		add(ok);
	}
}
			
	



